import React, { Component } from 'react'

export default class App extends Component {
    state = {
        count: 1
    }
    render() {
        return (
            <div>
                {this.state.count}
                <br />
                <button onClick={this.handleAdd1}>Add1</button>
                <button onClick={this.handleAdd2}>Add2</button>
            </div>
        )
    }

    handleAdd1 = () => {
        this.setState({ count: this.state.count + 1 }, () => { console.log(this.state.count) })
        console.log(this.state.count)
        this.setState({ count: this.state.count + 1 })
        console.log(this.state.count)
        this.setState({ count: this.state.count + 1 })
        console.log(this.state.count)
    }

    handleAdd2 = () => {
        setTimeout(() => {
            this.setState({ count: this.state.count + 1 })
            console.log(this.state.count)
            this.setState({ count: this.state.count + 1 })
            console.log(this.state.count)
            this.setState({ count: this.state.count + 1 })
            console.log(this.state.count)
        }, 0);
    }
}
